/**
 * 认证管理API
 */

import type {
  CaptchaResponse,
  CaptchaValidateRequest,
  LoginRequest,
  LoginResponse,
  UserInfo
} from "./type"
import { http } from "@/http/index"

/** 认证管理API */
export const authApi = {
  /**
   * 用户登录
   * @param params 登录请求参数
   */
  login: (params: LoginRequest) => {
    return http.post<LoginResponse>("/auth/login", params)
  },

  /**
   * 用户登出
   */
  logout: () => {
    return http.post<void>("/auth/logout")
  },

  /**
   * 刷新Token
   * @param refreshToken 刷新令牌
   */
  refreshToken: (refreshToken: string) => {
    return http.post<LoginResponse>("/auth/refresh", null, {
      params: { refreshToken }
    })
  },

  /**
   * 获取验证码
   */
  getCaptcha: () => {
    return http.get<CaptchaResponse>("/auth/captcha")
  },

  /**
   * 刷新验证码
   * @param captchaId 验证码ID
   */
  refreshCaptcha: (captchaId?: string) => {
    return http.post<CaptchaResponse>("/auth/captcha/refresh", null, {
      params: { captchaId }
    })
  },

  /**
   * 验证验证码
   * @param params 验证码验证参数
   */
  validateCaptcha: (params: CaptchaValidateRequest) => {
    return http.post<boolean>("/auth/captcha/validate", null, {
      params
    })
  },

  /**
   * 获取当前用户信息
   */
  getCurrentUser: () => {
    return http.get<UserInfo>("/auth/me")
  },

  /**
   * 检查登录状态
   */
  checkLoginStatus: () => {
    return http.get<boolean>("/auth/check")
  }
}

export * from "./type"
